package com.example.order.service.fallback;

import com.example.order.service.InventoryApiService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * InventoryApiService 调用库存微服务 的降级工厂配置而已,吱吱
 *
 * @author james
 */
@Component
public class InventoryApiServiceFallbackFactory implements FallbackFactory<InventoryApiService> {

    @Override
    public InventoryApiService create(Throwable cause) {
        // StackTraceElement[] stackTrace = cause.getStackTrace();
        // for (StackTraceElement traceElement : stackTrace) {
        //     System.out.println(traceElement.toString());
        // }
        return (productId, stock) -> String.format("订单创建返回你要减少商品ID:%d的库存请求,超过了规定时间未返回,所以进行降级操作,原因是:%s", productId, cause.getMessage());
    }
}